package com.handinfo.game;

import javax.microedition.lcdui.Graphics;

import com.handinfo.engine.GameManager;
import com.handinfo.uimenu.UITools;
import com.handinfo.util.Tools;

/**
 * 消耗类
 * @author venizeng
 * 
 */
public class ActorItemConsume extends ActorItem
{
	public int m_cd_type;// 类型(0,1,2,)
	public long m_time_cd;// cd时间
	
	public void drawIcon(Graphics g, int x, int y, int anchor)
	{
		super.drawIcon(g, x, y, anchor);
		if (!GameManager.getInstance().m_role.isCding(this.m_cd_type)) {//可以使用
			return ;
		}
		long time_cd_use = GameManager.getInstance().m_role.getCdTime(m_cd_type);
		if (time_cd_use == -1) {//未启用cd
			return ;
		}
		time_cd_use = time_cd_use > m_time_cd ? m_time_cd: time_cd_use ;
		x+= (UITools.W_BAG - GameScene.SIZE_IMG_ICON[0] >> 1) ;
		y+= (UITools.H_BAG - GameScene.SIZE_IMG_ICON[1] >> 1) ;
		paintCd(g,x,y,time_cd_use);//绘制cd
	}
	
	private void paintCd(Graphics g,int x,int y,long time_use){
		if(m_time_cd <= 0){
			return ;
		}
		
		int clipX = g.getClipX();
		int clipY = g.getClipY();
		int clipW = g.getClipWidth();
		int clipH = g.getClipHeight();
		// 绘制CD时的阴影
		int w = GameScene.SIZE_IMG_ICON[0] ;
		int h = GameScene.SIZE_IMG_ICON[1];
		g.setClip(x, y, w,h);
		int startDegree= 90 ;
		int endDegree = (int) (time_use * 360 /m_time_cd);
		endDegree = 360 - endDegree ;
		Tools.fillArc(g, GameManager.COLOR_ACTOR_SHADOW, x + (w>>1), y+ (h>>1),w << 1, startDegree,endDegree);
		g.setClip(clipX, clipY, clipW, clipH);
	}

}
